package doh.client;

import javax.swing.table.*;
import java.util.*;
import doh.service.*;
import doh.util.*;

public class LadderPanel extends javax.swing.JPanel {
    private TableModel model_ladder;

    /** Creates new form LadderPanel */
    public LadderPanel(UserSessionBeanRemote aBean) {
        UserSessionBeanRemote usb = aBean;
        String[] ladderHeader = {"Player ID", "ELO Rating"};
        List<LadderEntry> ladder = usb.getLadder();
        int tableLength = ladder.size();
        Object [][] ladderContent = new Object[tableLength][2];
        Iterator itr = ladder.iterator();
        int ii = 0;
        while (itr.hasNext()) {
            LadderEntry anEntry = (LadderEntry)itr.next();
            ladderContent[ii][0] = anEntry.player;
            ladderContent[ii][1] = anEntry.rating;
            ii++;
        }
        model_ladder = new javax.swing.table.DefaultTableModel(ladderContent, ladderHeader);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LadderTableScrollPane = new javax.swing.JScrollPane();
        LadderTable = new javax.swing.JTable();

        setMaximumSize(new java.awt.Dimension(800, 600));

        LadderTable.setModel(model_ladder);
        LadderTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        LadderTableScrollPane.setViewportView(LadderTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addComponent(LadderTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 737, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(LadderTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(177, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable LadderTable;
    private javax.swing.JScrollPane LadderTableScrollPane;
    // End of variables declaration//GEN-END:variables

}